package com.oocl.thread;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import javax.swing.JOptionPane;

import com.oocl.chat.pojo.Message;
import com.oocl.chat.util.JsonConvertor;
/**
 * 
 * @author EvanHuang
 * 专门处理发信息到服务器的线程。UI变化的处理在主线程中处理
 */
public class SendThread implements Runnable{
	private BufferedWriter writer;
	private Message message;
	public SendThread(BufferedWriter writer,Message message) throws Exception {
		super();
		this.writer = writer;
		this.message = message;
	}
	
	public void run() {
		try {
			writer.write(new JsonConvertor(message).getJsonString()+"\n");
			writer.flush();
		} catch (IOException e) {
			JOptionPane.showMessageDialog(null,
					"Can not connect to server , please check!", "Reminder", 1);
			System.out.println("服务器已下线");
		}
	}
	
}
